# -*- coding: utf-8 -*-

# @File    : router_dispatcher.py
# @Date    : 2025-02-19
# @Author  : gaoyuan
from multiprocessing import Pipe
import asyncio

class routeDispatcher():
    def __init__(self,config, pipe:Pipe):
        '''
         根据config中的信息
        1. 建立redis连接池
        :param config:
        :param pipe:
        '''
        # 所有的集卡路径
        self.tk_route
        self.pipe=pipe
        pass


    async def receive_route(self,):
        while True:
            if self.pipe.poll():
                new_route= self.pipe.recv()

                '''
                1. 清空 旧路径
                2. 更新 新路径
                '''
            await asyncio.sleep(0.01)

    async def dispatch(self):
        while True:
            '''
            根据当前时刻，在self.tk_route 中找到需要发送的路径，发送到redis
            并在self.tk_route中，删除当前时刻旧路径
            '''
            await asyncio.sleep(2)


def routeDispatcher_entry(config,pipe:Pipe):
    route_dispatcher=routeDispatcher(config=config,pipe=pipe)
    loop = asyncio.get_event_loop()
    loop.run_until_complete(asyncio.gather(

        route_dispatcher.receive_route(),
        route_dispatcher.dispatch()
    ))
    loop.close()